#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
int n, s, ans, a[8009], b[8009]; bool ok, ok1, ok2;
int main()
{
	freopen("build.in", "r", stdin), freopen("build.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	cin >> n, ans = n + 1;
	For(i, 1, n) cin >> a[i], b[i] = i;
	do
	{
		ok = true;
		For(l, 1, n)
		{
			For(r, l + 1, n)
			{
				ok1 = ok2 = false;
				For(i, l + 1, r - 1) ok1 |= b[i] > max(b[l], b[r]), ok2 |= b[i] < min(b[l], b[r]);
				if ( ok1 && ok2 ) { ok = false; break; }
			}
			if ( !ok ) break;
		}
		if ( ok ) { s = 0; For(i, 1, n) s += a[i] != b[i]; ans = min(ans, s); }
	}
	while ( next_permutation(b + 1, b + n + 1) );
	return cout << ans << '\n', 0;
}